begin
  require 'thread'
  require 'drb/drb'
  require 'drb/observer'
  require 'drb/timeridconv'
  require 'logger'
  require 'singleton'
  require 'digest/md5'
  require 'yaml'
  require 'monitor'
  require 'find'
  require 'logger'
  
  # base class
  require File.dirname(__FILE__) + '/lib/active_background.rb'
  
  # setup our client/server
  require File.dirname(__FILE__) + '/lib/active_background/server.rb'
  require File.dirname(__FILE__) + '/lib/active_background/client.rb'
  
  # we needs some people to help us out with the jobs
  require File.dirname(__FILE__) + '/lib/active_background/manager.rb'
  require File.dirname(__FILE__) + '/lib/active_background/assistent.rb'
  
  # archive processed and failed jobs
  require File.dirname(__FILE__) + '/lib/active_background/archive.rb'
  require File.dirname(__FILE__) + '/lib/active_background/archive_handlers/database.rb'
  require File.dirname(__FILE__) + '/lib/active_background/archive_handlers/file.rb'
  require File.dirname(__FILE__) + '/lib/active_background/archive_handlers/yaml.rb'
  
  # some helper classes to make configuration more efficient
  require File.dirname(__FILE__) + '/lib/active_background/configuration.rb'
  
  # database
  require File.dirname(__FILE__) + '/lib/active_background/database.rb'
  
  # worker management
  require File.dirname(__FILE__) + '/lib/active_background/job.rb'
  require File.dirname(__FILE__) + '/lib/active_background/jobs/worker.rb'
  require File.dirname(__FILE__) + '/lib/active_background/jobs/queue.rb'
  
  # a way to communicate with the server without being consired
  # of all the connection, configuration and job management details.
  require File.dirname(__FILE__) + '/lib/active_background/middle_man.rb'
  
  require File.dirname(__FILE__) + '/lib/active_background/handler.rb'
  
  # Initialize ActiveBackground and return config
  ACTIVE_BACKGROUND_CONFIG = ActiveBackground::Initializer.init
  ActiveBackground::Initializer.environment(ACTIVE_BACKGROUND_ENV) if defined?(ACTIVE_BACKGROUND_ENV)
  # lets include some libraries we need
  require 'active_record' if ACTIVE_BACKGROUND_CONFIG.database.lib_type == :active_record
  require 'og' if ACTIVE_BACKGROUND_CONFIG.database.lib_type == :og
  # complete configuration
  ActiveBackground::Initializer.run
  
  # Retrieve logger
  ACTIVE_BACKGROUND_LOGGER = ACTIVE_BACKGROUND_CONFIG.logger
  # Configure MiddleMan
  # TODO: need to create a Proxy object
  MiddleMan = ActiveBackground::MiddleManProxy.instance
rescue Exception => e
  Logger.new(File.dirname(__FILE__) + '/log/active_background.log').error(
                        "\n******ERROR-ERROR-ERROR-ERROR-ERROR******\n" +
                        "Exception: #{e.to_s} - (#{e.class})\n" +
                        "Manager: Failed booting Active Background\n" +
                        "----------------BACKTRACE-----------------\n" +
                                e.backtrace.join("\n") + "\n" +
                        "-------------------END--------------------\n" +
                        "\n******************************************\n" 
                        )
end